package org.xbdframework.sample.sso.crm.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system")
public class SystemController {

    @Value("${spring.application.name}")
    private String name;

    @Value("${spring.application.version}")
    private String version;

    @Value("${oa.profile-uri}")
    public String oaProfileUri;

    @RequestMapping("/profile")
    public Object profile(Model model) {
        model.addAttribute("name", name);
        model.addAttribute("version", version);
        model.addAttribute("oaProfileUri", oaProfileUri);

        return "system/profile";
    }

    @PreAuthorize("hasAuthority('hi')")
    @GetMapping("hi")
    public String hi(){

        return "hi ~~~~~";
    }

    @PreAuthorize("hasAuthority('go')")
    @GetMapping("go")
    public String go(){

        return "go ~~~~~";
    }

    @PreAuthorize("hasAuthority('run')")
    @GetMapping("run")
    public String run(){

        return "run ~~~~~";
    }

}
